package com.splic.web.controller.product;

import java.util.List;
import com.splic.common.utils.StringUtils;
import com.splic.product.domain.Product;
import com.splic.product.service.ProductService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.splic.common.annotation.Log;
import com.splic.common.enums.BusinessType;
import com.splic.product.domain.VoiceTransfer;
import com.splic.product.service.VoiceTransferService;
import com.splic.common.core.controller.BaseController;
import com.splic.common.core.domain.AjaxResult;
import com.splic.common.utils.poi.ExcelUtil;
import com.splic.common.core.page.TableDataInfo;

/**
 * 转写事件Controller
 * 
 * @author singe
 * @date 2023-08-17
 */
@Controller
@RequestMapping("/product/transfer")
public class VoiceTransferController extends BaseController
{
    private String prefix = "product/transfer";

    @Autowired
    private VoiceTransferService voiceTransferServiceImpl;
    @Autowired
    private ProductService productServiceImpl;

    @RequiresPermissions("product:transfer:view")
    @GetMapping()
    public String transfer(ModelMap mmap)
    {
        List<Product> productList = productServiceImpl.selectProductList(null);
        mmap.put("productList",productList);
        return prefix + "/list";
    }

    /**
     * 查询转写事件列表
     */
    @RequiresPermissions("product:transfer:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VoiceTransfer voiceTransfer)
    {
        startPage();
        List<VoiceTransfer> list = voiceTransferServiceImpl.selectVoiceTransferList(voiceTransfer);
        if (list != null && list.size() > 0) {
            for (VoiceTransfer transfer : list) {
                if (transfer.getStatus() == 5) {
                    transfer.setResultContent("1");
                }
            }
        }
        return getDataTable(list);
    }

    /**
     * 新增转写事件
     */
    @GetMapping(value = { "/form/{id}", "/form" })
    public String form(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id)){
            mmap.put("voiceTransfer", voiceTransferServiceImpl.selectVoiceTransferById(id));
        }else{
            mmap.put("voiceTransfer", new VoiceTransfer());
        }
        return prefix + "/form";
    }


    /**
     * 新增保存转写事件
     */
    @RequiresPermissions("product:transfer:edit")
    @Log(title = "转写事件", businessType = BusinessType.INSERT)
    @PostMapping("/saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(VoiceTransfer voiceTransfer)
    {
        return toAjax(voiceTransferServiceImpl.saveOrUpdate(voiceTransfer));
    }

    /**
     * 删除
     */
    @RequiresPermissions("product:transfer:remove")
    @Log(title = "转写事件", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id)
    {
        return toAjax(voiceTransferServiceImpl.deleteById(id));
    }


    /**
     * 导出转写事件列表
     */
    @RequiresPermissions("product:transfer:export")
    @Log(title = "转写事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VoiceTransfer voiceTransfer)
    {
        List<VoiceTransfer> list = voiceTransferServiceImpl.selectVoiceTransferList(voiceTransfer);
        ExcelUtil<VoiceTransfer> util = new ExcelUtil<VoiceTransfer>(VoiceTransfer.class);
        return util.exportExcel(list, "转写事件数据");
    }

    /**
     * 详情
     */
    @GetMapping(value = { "/lookDesc/{id}"})
    public String channelList(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        mmap.put("value", voiceTransferServiceImpl.selectVoiceTransferById(id).getResultContent());
        return prefix + "/desc";
    }
}
